package com.custom.base.util

import android.text.TextUtils

object PhoneUtil {
    /**
     * 设置手机号中间用*表示
     * @param mobile
     * @return
     */
    fun hideMobile(mobile: String,start:Int = 3,end:Int = 4): String {
        var result = mobile
        if (mobile.length>start+end&&!TextUtils.isEmpty(mobile) && TextUtils.isDigitsOnly(mobile)) {
            result = mobile.substring(0, start) + setLength(mobile.length-start-end) + mobile.substring(mobile.length-end)
        }
        return result
    }

    private fun setLength(length:Int):String{
        var a = ""
        for (i in 1..length){
            a += "*"
        }
        return a
    }
}